package com.runen.wnhz.runen.ui.adapter.puadapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.runen.wnhz.runen.R;
import com.runen.wnhz.runen.bean.CourseDetailCommentBean;
import com.runen.wnhz.runen.bean.PingLunBean;
import com.runen.wnhz.runen.bean.WantLearnBean;
import com.runen.wnhz.runen.common.utils.ACacheUtlis;
import com.runen.wnhz.runen.common.utils.NetUtils;
import com.runen.wnhz.runen.common.utils.OkHttpUtils;
import com.runen.wnhz.runen.common.utils.ToastUtil;
import com.runen.wnhz.runen.data.entity.UserBean;
import com.runen.wnhz.runen.ui.activity.login.LoginForPersonalActivity;
import com.runen.wnhz.runen.ui.fragment.minem.MessageFragment;
import com.runen.wnhz.runen.widget.coustomview.CircleImageView;

import org.simple.eventbus.EventBus;

import java.io.IOException;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;

public class CourseCommentRecordRecyclerAdapter extends RecyclerView.Adapter<CourseCommentRecordRecyclerAdapter.ViewHolder> {

    private Context context;

    private List<CourseDetailCommentBean.DataBean.ListBean.SlistBean> listBeans;

    private String lid;

    private boolean hasGivenThumbsUp = false;

    private String token;

    private  WantLearnBean wantLearnBean = null;

    private int position;

    private MessageFragment messageFragment;

    public void setMessageFragment(MessageFragment messageFragment) {
        this.messageFragment = messageFragment;
    }


    public CourseCommentRecordRecyclerAdapter(Context context, List<CourseDetailCommentBean.DataBean.ListBean.SlistBean> listBeans, String lid) {
        this.context = context;
        this.listBeans = listBeans;
        this.lid = lid;
        ACacheUtlis cacheUtlis = ACacheUtlis.getInstance();
        if (cacheUtlis != null) {
            UserBean reqeustUser = cacheUtlis.getReqeustUser(context);
            if (reqeustUser != null) {
                token = reqeustUser.getToken();
            }
        }
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = View.inflate(context, R.layout.comment_contentrecord_item_layout, null);
        CourseCommentRecordRecyclerAdapter.ViewHolder viewHolder  = new CourseCommentRecordRecyclerAdapter.ViewHolder(itemView);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, int position) {
        final CourseDetailCommentBean.DataBean.ListBean.SlistBean listBean = listBeans.get(position);
        holder.commentrecordUserName.setText(listBean.getUsername() +":");
        holder.commentrecordContent.setText(listBean.getContent());
    }

    @Override
    public int getItemCount() {
        if (listBeans != null) {
            return listBeans.size();
        } else {
            return 0;
        }
    }


    class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.text_commentrecordUserName)
        TextView commentrecordUserName;
        @BindView(R.id.rtText_commentrecordContent)
        TextView commentrecordContent;



        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
